<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Expires" CONTENT="-1">
<link rel="shortcut icon" href="images/favicon.png">
<link rel="icon" href="images/favicon.png">
<title>ASUS Wireless Router <#Web_Title#> - <#errormessage_title#></title>                          
<link rel="stylesheet" type="text/css" href="index_style.css">
<link rel="stylesheet" type="text/css" href="form_style.css">
<link rel="stylesheet" type="text/css" href="other.css">

<script type="text/JavaScript" src="/jquery.js"></script>
<script type="text/javascript">
var manually_stop_wan = '<% nvram_get_x("", "manually_disconnect_wan"); %>';
var ifEthernetConnect = <%detect_if_wan();%>;
var detect_dhcp_pppoe = "<% detect_dhcp_pppoe(); %>";
var wan_status_log = "<% get_wan_status_log(); %>";
var current_lanip = '<% nvram_get_x("", "lan_ipaddr_t"); %>';
var current_mask = '<% nvram_get_x("", "lan_netmask_t"); %>';
var new_lan_ip = '';
var reboot_time = 40;
var check_system_time = 0;

var wan_status_t = "";
var done_setting_lan = 0;

var winH, winW;
var progress, y;

var casenum = '<% get_parameter("flag"); %>';

function initial(){
	var html_code = '';
	
	hideLinkTag();
	
	if(casenum == 1){
		showtext($("#failReason1")[0], "<#web_redirect_reason1#>");
		
		$("#case1").show();
	}
	else if(casenum == 2){
		if(wan_status_log.indexOf("Failed to authenticate ourselves to peer") >= 0){
			showtext($("#failReason1")[0], "<#web_redirect_reason2_1#>");
			
			$("#ppp_input_error").show();
		}
		else{
			showtext($("#failReason1")[0], "<#web_redirect_reason2_2#>");
			
			$("#ppp_no_response").show();
		}
		
		$("#case2").show();
	}
	else if(casenum == 3){
		if(detect_dhcp_pppoe=="dhcp"){
			showtext($("#failReason1")[0], "<#web_redirect_reason3_1#>");
			
			$("#case3").show();
		}
		else{
			showtext($("#failReason1")[0], "<#web_redirect_reason3_2#>");
		}
	}
	else if(casenum == 4){
		showtext($("#failReason1")[0], "<#web_redirect_reason4#>");
		
		$("#case4").show();
	}
	else if(casenum == 5){
		if(manually_stop_wan == "1")
			showtext($("#failReason1")[0], "<#web_redirect_reason5_1#>");
		else
			showtext($("#failReason1")[0], "<#web_redirect_reason5_2#>");
		
		html_code += '<ul>\n';
		if(manually_stop_wan == "1")
			html_code += '<li><#web_redirect_suggestion5_1#></li>\n';
		else
			html_code += '<li><#web_redirect_suggestion5_2#></li>\n';
		html_code += '</ul>\n';
		
		if(manually_stop_wan == "1"){
			html_code += '<ul>\n';
			html_code += '<li><a href="javascript:manually_start_wan_Link();"><#web_redirect_suggestion_manually_start_wan#></a></li>\n';
			html_code += '</ul>\n';
		}
		
		$("#case5")[0].innerHTML = html_code;
		$("#case5").show();
	}
	else if(casenum == 6){
		new_lan_ip = get_new_lanip();
		
		showtext($("#failReason1")[0], "<#web_redirect_reason6#>");
		
		showtext($("#suggestion_title")[0], "<#web_redirect_suggestion0#>:");
		
		html_code += "<ul>\n";
		html_code += "<li><#web_redirect_case6_desc1#><br>";
		html_code += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>"+new_lan_ip+"</B></li>\n";
		html_code += "<li><#web_redirect_case6_desc2#></li>\n";
		html_code += "</ul>\n";
		html_code += "<br>\n";
		html_code += "<div style=\"text-align: right;\">\n";
		html_code += "<input type=\"button\" class=\"sbtn\" width=\"72\" onclick=\"change_lan_subnet();\" value=\"<#CTL_next#>\">\n";
		html_code += "</div>\n";
		
		$("#case6")[0].innerHTML = html_code;
		$("#case6").show();
		$("#suggestion").hide();
	}
	else{
		parent.location = "/index.asp";
	}
}

function showtext(obj, str){
	if(obj)
		obj.innerHTML = str;
}

function hideLinkTag(){
	if(document.all){
		var tagObjs = document.all.tags("a");
		
		for(var i = 0; i < tagObjs.length; ++i)
			tagObjs(i).outerHTML = tagObjs(i).outerHTML.replace(">"," hidefocus=true>");
	}
}

function wanLink(){
	location.href = "/Advanced_WAN_Content.asp";
}

function pppoeLink(){
	location.href = "/QIS_wizard.htm?flag=pppoe";
}

function detectLink(){
	location.href = "/QIS_wizard.htm?flag=detect";
}

function manually_start_wan_Link(){
	location.href = "/index.asp?flag=Internet";
}

function change_lan_subnet(){
	showLoadingBar(reboot_time);
	
	send_setting();
	
	setTimeout("check_system_ready();", reboot_time*1000);
}

function check_system_ready(){
	if(wan_status_t == ""){
		$("#proceeding_action")[0].innerHTML = "<#error_page_lanip_changed_desc1#>";
		detect_router();
		setTimeout("check_system_ready();", 3000);
	}
	else{
		$("#proceeding_img")[0].style.width = "100%";
		$("#proceeding_img_text")[0].innerHTML = "<#Main_alert_proceeding_desc3#>";
		$("#proceeding_action")[0].innerHTML = "<#APSurvey_action_renew_success#>";
		
		setTimeout("parent.location = \"http://"+new_lan_ip+"/QIS_wizard.htm?flag=detect\"", 2*1000);
	}
}

function send_setting(){
	$.ajax({
		url: '/setting_lan.htm',
		dataType: 'script',
		
		error: function(xhr){
			setTimeout("send_setting();", 1000);
		},
		success: function(response){
			;
		}
	});
}

function detect_router(){
	$.ajax({
		url: 'http://'+new_lan_ip+'/WAN_info.asp',
		dataType: 'script',
		
		error: function(xhr){
			setTimeout("detect_router();", 1000);
		},
		success: function(response){
			setTimeout("detect_router();", 1000);
		}
	});
}

function get_new_lanip(){
	var reverse_mask_num = ~(inet_aton(current_mask));
	var current_lanip_num = inet_aton(current_lanip);
	var new_lanip_num = current_lanip_num+reverse_mask_num+1;
	
	return inet_ntoa(new_lanip_num);
}

function inet_aton(ip_str){
	if(!ip_str)
		return -1;
	
	var re = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
	if(re.test(ip_str)){
		var v1 = parseInt(RegExp.$1);
		var v2 = parseInt(RegExp.$2);
		var v3 = parseInt(RegExp.$3);
		var v4 = parseInt(RegExp.$4);
		
		if(v1 < 256 && v2 < 256 && v3 < 256 && v4 < 256)
			return v1*256*256*256+v2*256*256+v3*256+v4;
	}
	
	return -2;
}

function inet_ntoa(ip_num){
	var v1, v2, v3, v4;
	var ip_str = "";
	
	if(!ip_num || typeof(ip_num) != "number")
		return null;
	
	v1 = (ip_num&0xff000000)>>>24;
	v2 = (ip_num&0x00ff0000)>>>16;
	v3 = (ip_num&0x0000ff00)>>>8;
	v4 = (ip_num&0x000000ff);
	
	ip_str = v1+"."+v2+"."+v3+"."+v4;
	
	return ip_str;
}

function winW_H(){
	if(parseInt(navigator.appVersion) > 3){
		winW = document.documentElement.scrollWidth;
		if(document.documentElement.clientHeight > document.documentElement.scrollHeight)
			winH = document.documentElement.clientHeight;
		else
			winH = document.documentElement.scrollHeight;
	}
} 

function showLoadingBar(seconds){
	htmlbodyforIE = document.getElementsByTagName("html");  //this both for IE&FF, use "html" but not "body" because <!DOCTYPE html PUBLIC.......>
	htmlbodyforIE[0].style.overflow = "hidden";	  //hidden the Y-scrollbar for preventing from user scroll it.
	
	winW_H();
	var blockmarginTop;
	blockmarginTop = document.documentElement.scrollTop + 200;
	$("#loadingBarBlock")[0].style.marginTop = blockmarginTop+"px";
	$("#LoadingBar")[0].style.width = winW+"px";
	$("#LoadingBar")[0].style.height = winH+"px";
	
	if(!seconds)
		seconds = 0;
	else
		progress = 100/seconds;
	
	y = 0;
	LoadingProgress(seconds);
}

function LoadingProgress(seconds){
	$("#LoadingBar")[0].style.visibility = "visible";
	
	y = y+progress;
	if(typeof(seconds) == "number" && seconds >= 0){
		if(seconds != 0){
			if(Math.round(y) == 100){
				$("#proceeding_img")[0].style.width = "99%";
				$("#proceeding_img_text")[0].innerHTML = "99%";
			}
			else{
				$("#proceeding_img")[0].style.width = Math.round(y) + "%";
				$("#proceeding_img_text")[0].innerHTML = Math.round(y) + "%";
			}
			--seconds;
			setTimeout("LoadingProgress("+seconds+");", 1000);
		}
		else{
			$("#proceeding_img")[0].style.width = "99%";
			$("#proceeding_img_text")[0].innerHTML = "99%";
			y = 0;
		}
	}
}

function hideLoadingBar(){
	$("#LoadingBar")[0].style.visibility = "hidden";
}
</script>
</head>

<body onload="initial();">
<div id="LoadingBar" class="popup_bar_bg" style="background-image: url(/images/popup_bg2.gif);">
<table cellpadding="5" cellspacing="0" id="loadingBarBlock" class="loadingBarBlock" align="center">
	<tr>
		<td height="80">
		<div class="Bar_container">
			<span id="proceeding_img_text" ></span>
			<div id="proceeding_img"></div>
		</div>
		<div id="proceeding_action" style="margin:5px auto; width:85%;">Changing the local subnet...</div>
		</td>
	</tr>
</table>
<!--[if lte IE 6.5]><iframe class="hackiframe"></iframe><![endif]-->
</div>

<br><br>
<table width="500" border="0" align="center" cellspacing="0" class="erTable">
<thead>
  <tr>
    <td height="52" align="left" valign="top"><span class="modelName" style="margin:25px 0px 0px 160px;"><#Web_Title#></span></td>
  </tr>
</thead>
  <tr>
    <th  valign="top" height="30" background="images/er_bg.gif"><div class="er_title"><#web_redirect_message#></div></th>
  </tr>
  

  <tr>
    <td  valign="top" background="images/er_bg.gif">
  	  <div class="alertImg"><img src="images/alertImg.gif"></div>
  	  <span class="Epagetitle"><#web_redirect_fail_reason0#> :</span>
	  
	  <div id="failReason" class="Epagecontent" style="color:#CC0000">
	    <ul>
		  <li>
		    <span id="failReason1"></span>
		  </li>
	    </ul>
	  </div>
	  
		<div class="Epagetitle">
			<span><#web_redirect_suggestion0#>: (<#web_redirect_suggestion0_1#>)</span>
		</div>
	<!--span id="suggestion_title" class="Epagetitle"><#web_redirect_suggestion0#>: (<#web_redirect_suggestion0_1#>)</span-->
	<div class="Epagecontent">
		<div id="case1" style="display:none;">
		  <ul>
			 <li><#web_redirect_suggestion1#></li>
		  </ul>
		</div>
		
		<div id="case2" style="display:none;">
		  <ul>
			 <li>
			 	<div id="ppp_input_error" style="display:none;">
			 	  <a href="javascript:pppoeLink();"><#web_redirect_suggestion2_1#></a>
			 	  <span><#web_redirect_suggestion2_1_desc#></span>
			 	</div>
			 	
			 	<div id="ppp_no_response" style="display:none;">
			 	  <a href="javascript:detectLink();"><#web_redirect_suggestion2_2#></a>
			 	  <span><#web_redirect_suggestion2_2_desc#></span>
			 	</div>
			 </li>
		  </ul>
		</div>
		
		<div id="case3" style="display:none;">
		  <ul>
			 <li><#web_redirect_suggestion3#></li>
		  </ul>
		</div>
		
		<div id="case4" style="display:none;">
		  <ul>	  	
			 <li><#web_redirect_suggestion4#></li>
		  </ul>
		</div>
		
		<div id="case5" style="display:none;"></div>
		
		<div id="case6" style="display:none;">
			<ul>
				<li><#web_redirect_suggestion6#></li>
			</ul>
		</div>
		
		<div id="suggestion" style="display:;">
		<ul>
		  <li>
		  	<span id="suggestion_final"><#web_redirect_suggestion_final#></span>
		  	<a id="selfsetting_link" href="javascript:wanLink();"><#web_redirect_suggestion_etc#></a>
		   	<span><#web_redirect_suggestion_etc_desc#></span>
		  </li>
		</ul>
		</div>
	  </div>
	</td>
  </tr>
  
  <tr>
    <td height="22" background="images/er_bottom.gif"><span></span></td>
  </tr>
</table>
</body>
</html>
